package br.com.portalaberto.connection.chain;

 
import javax.microedition.io.*;

public class BasicAuthHandler implements Handler {
 
  private String username;
  private String password;
 
  public BasicAuthHandler (String u, String p) {
    username = u;
    password = p;
  }
 
  public void prepareHeaders(HttpConnection c) throws Exception {
    String s = encode(username + ":" + password);
    c.setRequestProperty("Authorization", s);
  }
 
  public boolean processHeaders (HttpConnection c) throws Exception {
    return false;
  }

  // Base64 encoding.
  //
  private String encode(String d) {
    return Base64.encode(d.getBytes());
  }
}
